package kr.saeildamil.androidforstudy2.ch23;

import kr.saeildamil.androidforstudy2.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnticipateInterpolator;
import android.view.animation.AnticipateOvershootInterpolator;
import android.view.animation.BounceInterpolator;
import android.view.animation.CycleInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.OvershootInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.Spinner;

public class AninamtionAttr extends Activity {
	
	ImageView mAnimTarget;
	CheckBox mBeforeCheck;
	CheckBox mAfterCheck;
	CheckBox mrRepeatCheck;
	CheckBox mReverseCheck;
	RadioGroup mRadio;
	Spinner mSpin;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch23_animationattr);
		
		mAnimTarget = (ImageView) findViewById(R.id.animtarget);
		mBeforeCheck = (CheckBox) findViewById(R.id.btnfillbefore);
		mAfterCheck = (CheckBox) findViewById(R.id.btnfillafter);
		mrRepeatCheck = (CheckBox) findViewById(R.id.btnrepeat);
		mReverseCheck = (CheckBox) findViewById(R.id.btnreverse);
		mSpin = (Spinner) findViewById(R.id.spininter);
		mSpin.setPrompt("Select Interpolator");
	
		ArrayAdapter<CharSequence> adspin = ArrayAdapter.createFromResource(this, R.array.interpolator, android.R.layout.simple_spinner_dropdown_item);
		adspin.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		mSpin.setAdapter(adspin);
		
	}
	
	public void mOnClick(View v){
	switch (v.getId()) {
	case R.id.btnstart:
		TranslateAnimation trans = new TranslateAnimation(0, 400, 0, 0);
		trans.setDuration(3000);
		trans.setFillBefore(mBeforeCheck.isChecked());
		trans.setFillAfter(mAfterCheck.isChecked());
		if(mrRepeatCheck.isChecked()){
			trans.setRepeatCount(1);
			if(mReverseCheck.isChecked()){
				trans.setRepeatMode(Animation.REVERSE);
			}
		}
		
		switch (mSpin.getSelectedItemPosition()) {
		case 0:
			trans.setInterpolator(new LinearInterpolator()); 
			break;
		case 1:
			trans.setInterpolator(new AccelerateInterpolator()); 
			break;
		case 2:
			trans.setInterpolator(new DecelerateInterpolator()); 
			break;
		case 3:
			trans.setInterpolator(new AccelerateDecelerateInterpolator()); 
			break;
		case 4:
			trans.setInterpolator(new AnticipateInterpolator()); 
			break;
		case 5:
			trans.setInterpolator(new BounceInterpolator()); 
			break;
		case 6:
			trans.setInterpolator(new CycleInterpolator(0.5f)); 
			break;
		case 7:
			trans.setInterpolator(new OvershootInterpolator()); 
			break;
		case 8:
			trans.setInterpolator(new AnticipateOvershootInterpolator()); 
			break;
		}
		mAnimTarget.startAnimation(trans);
		break;
	}	
	}
}

